package com.jrzn.base;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nsjr.jrznandroid.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by haokai on 2016/5/12.
 */
public class BaseActivity  extends AppCompatActivity{
    public TextView tv, tv_left, tv_right;
    private ImageView iv1_right, iv2_right, iv_left;
    public LinearLayout back, add, color;
    protected BaseActivity self;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         self=this;
    }
    /**
     * 设置title标题 不同type不同布局
     * @param title
     * @param left_drawable
      * 0为没�? 1为默认图�? 也可输入res地址自定义图�?
     */
    public void initTitleIcon(String title, int left_drawable,
                              int right_drawable_1, int right_drawable_2) {
        tv = (TextView) findViewById(R.id.app_title);
        iv1_right = (ImageView) findViewById(R.id.app_title_iv1_right);
        iv2_right = (ImageView) findViewById(R.id.app_title_iv2_right);
        iv_left = (ImageView) findViewById(R.id.app_title_iv_left);
        back = (LinearLayout) findViewById(R.id.app_back_click);
        color = (LinearLayout) findViewById(R.id.app_title_color);
        add = (LinearLayout) findViewById(R.id.app_add_click);
        tv.setText(title);
        switch (left_drawable) {
            case 0:
                iv_left.setVisibility(View.GONE);
                break;
            case 1:
                iv_left.setVisibility(View.VISIBLE);
                break;
            default:
                iv_left.setVisibility(View.VISIBLE);
                iv_left.setImageResource(left_drawable);
                break;
        }
        switch (right_drawable_1) {
            case 0:
                iv1_right.setVisibility(View.GONE);
                break;
            case 1:
                iv1_right.setVisibility(View.VISIBLE);
                break;

            default:
                iv1_right.setVisibility(View.VISIBLE);
                iv1_right.setImageResource(right_drawable_1);
                break;
        }
        switch (right_drawable_2) {
            case 0:
                iv2_right.setVisibility(View.GONE);
                break;
            case 1:
                iv2_right.setVisibility(View.VISIBLE);
                break;
            default:
                iv2_right.setVisibility(View.VISIBLE);
                iv2_right.setImageResource(right_drawable_2);
                break;
        }
        back.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                onBackPressed();
            }
        });
    }

    /**
     * 自定义修改title左右文字
     *
     * @param left_text
     * @param right_text
     */
    public void initTitleText(String left_text, String right_text) {
        tv_left = (TextView) findViewById(R.id.app_title_tv_left);
        tv_right = (TextView) findViewById(R.id.app_title_tv_right);
        if (!TextUtils.isEmpty(left_text)) {
            tv_left.setText(left_text);
            tv_left.setVisibility(View.VISIBLE);
        } else {
            tv_left.setVisibility(View.INVISIBLE);
        }
        if (!TextUtils.isEmpty(right_text)) {
            tv_right.setText(right_text);
            tv_right.setVisibility(View.VISIBLE);
        } else {
            tv_right.setVisibility(View.INVISIBLE);
        }
    }
    /**
     * 设置标题栏的背景颜色
     *
     * @param color
     */

    protected void initTitleColor(int color) {
        this.color.setBackgroundColor(color);
    }
    /**
     * 设置返回时界面动�?
     */

    public void onBackPressed() {
        finish();
        super.onBackPressed();
    }

    /**
     * 跳转界面使得动画
     *
     * @param
     * @param ac
     */

    public void toActivity(Class<? extends Activity> ac) {
        Intent intent = new Intent(this, ac);
        startActivity(intent);
    }

    /**
     * 跳转界面使得动画
     *
     * @param context
     * @param ac
     */

    public void toActivity(Context context, Class<? extends Activity> ac) {
        Intent intent = new Intent(context, ac);
        startActivity(intent);
    }

    public void toActivity(Context context, Class<? extends Activity> ac,
                           String str) {
        Intent intent = new Intent(context, ac);
        intent.putExtra("bundle", str);
        startActivity(intent);
    }

    public void toActivity(Context context, Class<? extends Activity> ac,
                           Bundle bundle) {
        Intent intent = new Intent(context, ac);
        intent.putExtras(bundle);
        startActivity(intent);

    }
    public void toResultActivity(Context context, Class<? extends Activity> ac,
                                 int requestCode) {

        Intent intent = new Intent(context, ac);
        startActivityForResult(intent, requestCode);

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }



}
